
import { MessageBox, Message } from 'element-ui'
import router from '@/router'
import { operateActionPost } from '@/api/interface/operate.js'


export function postOperateApi(operate, params){
    operateActionPost(operate.formModel.url + operate.key + 'Action/', params).then((res) => {
        if(res.data.code == 10000){
            Message({
                message: res.data.data,
                type: 'success',
                duration: 3 * 1000
            })
            if(operate.key == 'save'){
                router.go(-1)
            }
        }
    })
}

export function operateAction(operate, params) {
    console.log('点击操作事件', operate, params)
    if(operate.actionType == 'api'){
        if(!operate.formModel.url){
            Message({
                message: '事件缺少url参数',
                type: 'error',
                duration: 3 * 1000
            })
            return
        }
        switch (operate.key) {
            case 'save':
                break
            case 'delete':
                break
            default:
                break;
        }
        operateActionPost(operate.formModel.url + operate.key + 'Action/', params).then((res) => {
            if(res.data.code == 10000){
                Message({
                    message: res.data.data,
                    type: 'success',
                    duration: 3 * 1000
                })
                if(operate.key == 'save'){
                    router.go(-1)
                }
            }
        })
    }else{
        switch (operate.key) {
            case 'create':
                router.push({name: 'Update', query: { formData: JSON.stringify(params.formData)}})
              break;
            case 'update':
                router.push({name: 'Update', query: {formData: JSON.stringify(params.formData), form: JSON.stringify(params.row)}})
              break;
            case 'back':
                router.go(-1)
                break;
            default:
                break;
        }
    }
  }